const util = require("./util");

module.exports = modules => {
    const maps = {};
    modules.forEach(m => {
        for(let key in m.map) {
            let [type, defaultValue, elementNames] = m.map[key];
            if(util.isUndefined(elementNames)) throw new Error(`${key} map element names invalid`);
            if(!util.isArray(elementNames)) elementNames = [elementNames];
            elementNames.forEach(name => {
                name = name.toLowerCase();
                !maps[name] && (maps[name] = {});
                maps[name][key] = [type, defaultValue];
            });        
        }
    });
    return maps;
};